package com.hadoop.project;

import com.hadoop.project.entity.constant.RedisComplexConstant;
import com.hadoop.project.entity.constant.ZhiGeConstant;
import com.hadoop.project.entity.hbase.HBaseResult;
import com.hadoop.project.gen.maodaligendata.GenConstant;
import com.hadoop.project.entity.hbase.ProcessRes;
import com.hadoop.project.mvc.service.hbase.HBaseService;
import com.hadoop.project.utils.Count;
import com.hadoop.project.utils.Processor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;

/**
 * @author Alexmaodali
 * @usage:项目启动后初始化操作 & 将hbase数据存入redis
 */
@Slf4j
@Component("initRun")
public class InitRun {

    @Autowired
    private HBaseService hBaseService;

    @Resource
    private RedisComplexConstant x;

    @PostConstruct
    public void run() throws Exception {
        try {
//            String tableName        = GenConstant.TableName;
//            log.info("\n\n开始读取hbase数据");
//            HBaseResult hBaseResult = hBaseService.getAll(tableName);
//            log.info("\n\n开始计算数据");
//            //毛哥原本的计算方式
//            //ProcessRes processRes   = Processor.processHBaseData(hBaseResult);
//
//            //智哥优化后的计算方式
//            ProcessRes processRes = Count.process(hBaseResult);
//
//
//            // 存入redis
//            x.saveData2Redis(processRes);
//
//            // 从redis获取hbase数据
//            ProcessRes dataFromRedis = x.getDataFromRedis();
//
//            // 智哥说要存一份文件 满足他
//            if (ZhiGeConstant.needSaveToZhiGe) {
//                log.info("\n\n开始写入数据");
//                ZhiGeConstant.writeInFile(processRes);
//            }


            log.info("\n\n项目存储hbase数据到Redis成功\n\n");
        } catch (Exception e) {
            log.error("\n\n项目存储hbase数据到Redis失败\n\n");
        }
    }
}
